home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-01-12 | 3.5 KB | 124 lines | [TEXT/PJMM] |
- {A unit for setting the screen depth.}
- {It follows the usual SAT standard for backwards compatibility - i.e. does NOT}
- {require Color QD!}
- {If you want to check/set for the main device, pass nil for the device. That way}
- {you can avoid all CQD-dependent calls in your own code.}
-
- {Note! This unit is independent of SAT. Thus, it can NOT inform SAT of the depth switch, but}
- {you have to do that yourself! Call SATDepthChangeTest to let SAT redraw all faces}
- {it can. Faces created with GetFaceFromPICT and other advanced ways are your responsability}
- {to update.}
-
- {Written in Juni-96, based on DepthSet. Tested och debugged september -96.}
-
- unit SATSetDepth;
-
- interface
- uses
- {$ifc undefined THINK_PASCAL}
- Types, QuickDraw, Events, Windows, Dialogs, Fonts, DiskInit, TextEdit, Traps, {}
- Memory, SegLoad, Scrap, ToolUtils, OSUtils, Menus, Resources, StandardFile,{}
- GestaltEqu, Files, Errors, Devices, {}
- {$elsec}
- InterfacesUI,
- {$endc}
- Palettes;
-
- function SATHasDepth (theDevice: GDHandle; desiredDepth: Integer): Boolean;
- function SATGetDepth (theDevice: GDHandle): Integer;
- function SATSetDepth (theDevice: GDHandle; desiredDepth: Integer): OSErr;
- function SATGetMode (theDevice: GDHandle): Boolean;
- function SATSetMode (theDevice: GDHandle; wantsColor: Boolean): OSErr;
- procedure SATRestoreDepth;
-
- implementation
-
- var
- savedDepth: Integer; {Set by SATSetDepth, used by SATRestoreDepth.}
-
- function HasColorQD: Boolean;
- var
- theWorld: SysEnvRec;
- begin
- HasColorQD := false;
- if SysEnvirons(1, theWorld) = noErr then
- HasColorQD := theWorld.hasColorQD;
- end; {HasColorQD}
-
- function SATHasDepth (theDevice: GDHandle; desiredDepth: Integer): Boolean;
- begin
- SATHasDepth := false;
- if not HasColorQD then
- SATHasDepth := desiredDepth = 1 {Unimplemented trap error}
- else
- begin
- if theDevice = nil then
- theDevice := GetMainDevice;
- SATHasDepth := 0 <> HasDepth(theDevice, desiredDepth, gdDevType, desiredDepth);
- end;
- end; {SATHasDepth}
-
- {Get the depth of a screen. When SAT is initialized, use gSAT.initDepth instead!}
- function SATGetDepth (theDevice: GDHandle): Integer;
- var
- err: OSErr;
- begin
- SATGetDepth := 1;
- if HasColorQD then
- begin
- if theDevice = nil then
- theDevice := GetMainDevice;
- SATGetDepth := theDevice^^.gdPMap^^.pixelSize;
- end;
- end; {SATGetDepth}
-
- {If you change the depth after SAT has initialized, don't forget to call}
- {SATDepthChangeTest!}
- function SATSetDepth (theDevice: GDHandle; desiredDepth: Integer): OSErr;
- var
- err: OSErr;
- begin
- if not HasColorQD then
- err := dsCoreErr {Unimplemented trap error}
- else
- begin
- if theDevice = nil then
- theDevice := GetMainDevice;
-
- { Remember old bit depth }
- {oldDepth := theDev^^.gdPMap^^.pixelSize;}
- { Change bit depth if available }
- if HasDepth(theDevice, desiredDepth, gdDevType, desiredDepth) <> 0 then
- begin
- savedDepth := theDevice^^.gdPMap^^.pixelSize;
- err := SetDepth(theDevice, desiredDepth, gdDevType, 1);
- end
- else
- ;
- end;
- SATSetDepth := err;
- end; {SATSetDepth}
-
- function SATGetMode (theDevice: GDHandle): Boolean;
- begin
- if not HasColorQD then
- SATGetMode := false
- else
- SATGetMode := TestDeviceAttribute(theDevice, gdDevType);
- end; {SATGetMode}
-
- function SATSetMode (theDevice: GDHandle; wantsColor: Boolean): OSErr;
- var
- err: OSErr;
- begin
- err := SetDepth(theDevice, theDevice^^.gdPMap^^.pixelSize, BSL(1, gdDevType), Integer(wantsColor));
- end; {SATSetMode}
-
- procedure SATRestoreDepth;
- begin
- if savedDepth <> 0 then
- if noErr <> SATSetDepth(nil, savedDepth) then
- ;
- end; {SATRestoreDepth}
-
- end.